package com.baitai.web.controller.system;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.baitai.common.utils.SecurityUtils;
import com.baitai.system.domain.ProductInfo;
import com.baitai.system.domain.UserPointsLog;
import com.baitai.system.domain.vo.PrizeDrawRuleVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baitai.common.annotation.Log;
import com.baitai.common.core.controller.BaseController;
import com.baitai.common.core.domain.AjaxResult;
import com.baitai.common.enums.BusinessType;
import com.baitai.system.domain.PrizeDrawRule;
import com.baitai.system.service.IPrizeDrawRuleService;
import com.baitai.common.utils.poi.ExcelUtil;
import com.baitai.common.core.page.TableDataInfo;

/**
 * 抽奖规则Controller
 * 
 * @author ruoyi
 * @date 2024-07-11
 */
@RestController
@RequestMapping("/system/prizeDrawRule")
public class PrizeDrawRuleController extends BaseController
{
    @Autowired
    private IPrizeDrawRuleService prizeDrawRuleService;

    /**
     * 查询抽奖规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:prizeDrawRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrizeDrawRule prizeDrawRule)
    {
        startPage();
        List<PrizeDrawRule> list = prizeDrawRuleService.selectPrizeDrawRuleList(prizeDrawRule);
        return getDataTable(list);
    }

    /**
     * 导出抽奖规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:prizeDrawRule:export')")
    @Log(title = "抽奖规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrizeDrawRule prizeDrawRule)
    {
        List<PrizeDrawRule> list = prizeDrawRuleService.selectPrizeDrawRuleList(prizeDrawRule);
        ExcelUtil<PrizeDrawRule> util = new ExcelUtil<PrizeDrawRule>(PrizeDrawRule.class);
        util.exportExcel(response, list, "抽奖规则数据");
    }

    /**
     * 获取抽奖规则详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(prizeDrawRuleService.selectPrizeDrawRuleById(id));
    }

    /**
     * 新增抽奖规则
     */
    @PreAuthorize("@ss.hasPermi('system:prizeDrawRule:add')")
    @Log(title = "抽奖规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrizeDrawRuleVo prizeDrawRule)
    {
        return toAjax(prizeDrawRuleService.insertPrizeDrawRule(prizeDrawRule));
    }

    /**
     * 修改抽奖规则
     */
    @PreAuthorize("@ss.hasPermi('system:prizeDrawRule:edit')")
    @Log(title = "抽奖规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrizeDrawRuleVo prizeDrawRule)
    {
        return toAjax(prizeDrawRuleService.updatePrizeDrawRule(prizeDrawRule));
    }

    /**
     * 删除抽奖规则
     */
    @PreAuthorize("@ss.hasPermi('system:prizeDrawRule:remove')")
    @Log(title = "抽奖规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prizeDrawRuleService.deletePrizeDrawRuleByIds(ids));
    }

    /**
     * 抽奖
     */
    @Log(title = "抽奖", businessType = BusinessType.OTHER)
    @GetMapping("PrizeDraw/{id}")
    public AjaxResult PrizeDraw(@PathVariable Long id)
    {
        return prizeDrawRuleService.PrizeDraw(id, SecurityUtils.getUserId());
    }

    /**
     * 抽奖规则
     */
    @Log(title = "获取当前激励奖池", businessType = BusinessType.OTHER)
    @GetMapping("getPrizeDraw")
    public AjaxResult getPrizeDraw()
    {
        return prizeDrawRuleService.getPrizeDraw();
    }
}
